<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="4" labelWidth="85" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="whmClainManagement"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <!--列操作
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button>
        <AjaxButton size="small" type="danger" :click="removeHandler">删除</AjaxButton>
      </template>
      -->
    </FilterTable>

    <!--抽屉 -->
    <Drawer :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <QualityModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </Drawer>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
// import { getExtendedOrder } from '@/api/claimManagement/business/repair'; // 页面调用的的方法,对应的路径连接后台
// 延保订单查询
export default {
  name: 'whm',
  components: {},
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: false },
      visible: false,
      visible1: false,
      dialogTitle: '',
      fetchApi: '',
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '延保单号',
          fieldName: 'ybdd',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'owberName',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'phone',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '产品周期',
          fieldName: 'productCycle',
          placeholder: '请输入...'
          // itemList: this.createDictList('1004')
        },
        {
          type: 'INPUT',
          label: '产品类型',
          fieldName: 'productType',
          placeholder: '请输入...'
          // itemList: this.createDictList('1004')
        },
        {
          type: 'INPUT',
          label: '核销方式',
          fieldName: 'writeOffMethod',
          placeholder: '请输入...'
          // itemList: this.createDictList('1004')
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: props => {
            // return (
            // <div>
            //   <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
            //     编辑
            //   </el-button>
            // </div>
            // );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '延保单号',
          dataIndex: 'ybdd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品周期',
          dataIndex: 'productCycle',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品类型',
          dataIndex: 'productType',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '核销方式',
          dataIndex: 'writeOffMethod',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆用途',
          dataIndex: 'writeOffMethod',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'model',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'dispose',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户姓名',
          dataIndex: 'owberName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '手机号',
          dataIndex: 'phone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建人',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建日期',
          dataIndex: 'createdAt',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        }
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      this.showHandler();
    },
    async removeHandler() {
      // 删除
      if (!this.tableData.length) {
        return this.$notify({
          title: '提示信息',
          message: '请选择数据',
          type: 'error'
        });
      }
      await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      });
      // console.log(999);
      await this.deleteDialog(); // 执行删除方法
      // console.log(999);
    },
    async deleteDialog() {
      // 取出数据id
      let res = {};
      this.ids = this.tableData.map(x => x.qualityId); // 获取选中页面的ID加到map集合中

      res = await deleteUsedCardQualitys({ ids: this.ids.join(',') });
      // alert("aaaaaa"+res);
      // console.log(res);
      // 判断结果
      // alert("aaaaa"+res.resultCode+"aaa");
      if (res.resultCode === 200) {
        // alert(this.res);
        // console.log(res.data);
        if (res.data) {
          this.fetchParams = { ...this.fetchParams }; // 重复新加载

          return this.$notify({
            // 提示信息
            title: '提示信息',
            message: '删除成功',
            type: 'success'
          });
        }
      }
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    showHandler() {
      // 显示
      this.dialogTitle = `${this.conf[this.handleType]}质保分类`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
